| Total Complexity | 2 |
| Total Lines | 30 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { Inject } from '@nestjs/common'; |
||
| 6 | |||
| 7 | @QueryHandler(GetEventsByPeriodQuery) |
||
| 8 | export class GetEventsByPeriodQueryHandler { |
||
| 9 | constructor( |
||
| 10 | @Inject('IEventRepository') |
||
| 11 | private readonly eventRepository: IEventRepository |
||
| 12 | ) {} |
||
| 13 | |||
| 14 | public async execute(query: GetEventsByPeriodQuery): Promise<EventView[]> { |
||
| 15 | const { fromDate, toDate } = query; |
||
| 16 | const eventViews: EventView[] = []; |
||
| 17 | const events = await this.eventRepository.findByPeriod(fromDate, toDate); |
||
| 18 | |||
| 19 | for (const event of events) { |
||
| 20 | const user = event.getPhotographer(); |
||
| 21 | const school = event.getSchool(); |
||
| 22 | const schoolInformation = `${school.getName()} - ${school.getReference()}`; |
||
| 23 | const userInformation = `${user.getFirstName()} ${user.getLastName()}`; |
||
| 24 | |||
| 25 | eventViews.push( |
||
| 26 | new EventView( |
||
| 27 | event.getId(), |
||
| 28 | `[${userInformation}] ${schoolInformation}`, |
||
| 29 | event.getDate(), |
||
| 30 | event.getSummary() |
||
| 31 | ) |
||
| 32 | ); |
||
| 33 | } |
||
| 34 | |||
| 35 | return eventViews; |
||
| 36 | } |
||
| 38 |